package com.webvihar.access2db.adapters;

import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.webvihar.access2db.R;
import com.webvihar.access2db.activities.DeleteSessionActivity;
import com.webvihar.access2db.activities.EditSessionActivity;
import com.webvihar.access2db.model.Session;

public class SessionAdapter extends BaseA2DbAdapter {

	private String SESSION_SESSION_NAME = "SessionName";
	private String SESSION_SESSION_HOST = "SessionHost";
	private String SESSION_SESSION_PORT = "SessionPort";
	private String SESSION_SESSION_USERNAME = "SessionUsername";
	private String SESSION_SESSION_PASSWORD = "SessionPassword";
	
	Context mContext;
	List<Session> sessions;
	
	public SessionAdapter(Context context, List<Session> sessions) {
		this.mContext = context;
		this.sessions = sessions;
	}
	
	@Override
	public int getCount() {
		return sessions.size();
	}

	@Override
	public Object getItem(int position) {
		return sessions.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		convertView = inflater.inflate(R.layout.session_list_item, null);		
		TextView sessionName = (TextView)convertView.findViewById(R.id.session_name_txt);
		TextView host = (TextView)convertView.findViewById(R.id.session_host_txt);
		//ImageView edit = (ImageView) convertView.findViewById(R.id.sessions_edit_btn);
		//ImageView delete = (ImageView) convertView.findViewById(R.id.sessions_delete_btn);
		final Session presentSessionItem = sessions.get(position);
		/*edit.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v){
				Intent intent = new Intent(mContext, EditSessionActivity.class);
				intent.putExtra(SESSION_SESSION_NAME, presentSessionItem.sessionName);
				intent.putExtra(SESSION_SESSION_HOST, presentSessionItem.host);
				intent.putExtra(SESSION_SESSION_PORT, presentSessionItem.port);
				intent.putExtra(SESSION_SESSION_USERNAME, presentSessionItem.username);
				intent.putExtra(SESSION_SESSION_PASSWORD, presentSessionItem.password);
				mContext.startActivity(intent);
			}
		});
		
		delete.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(mContext, DeleteSessionActivity.class);
				intent.putExtra(SESSION_SESSION_NAME, presentSessionItem.sessionName);
				intent.putExtra(SESSION_SESSION_HOST, presentSessionItem.host);
				intent.putExtra(SESSION_SESSION_PORT, presentSessionItem.port);
				intent.putExtra(SESSION_SESSION_USERNAME, presentSessionItem.username);
				intent.putExtra(SESSION_SESSION_PASSWORD, presentSessionItem.password);
				mContext.startActivity(intent);
			}
		});
	*/
		
		Session session = sessions.get(position);
		sessionName.setText(session.sessionName);
		host.setText(session.host);
		return convertView;
	}

}
